/*
 * SDLEventDispatcher.h
 *
 *  Created on: Jun 17, 2010
 *      Author: Ry
 */

#ifndef SDLEVENTDISPATCHER_H_
#define SDLEVENTDISPATCHER_H_

#include <vector>
#include <SDL/SDL_events.h>
#include "SDLEventHandler.h"
#include "EventDispatcher.h"

class SDLEventDispatcher: public EventDispatcher {
protected:
	std::vector<SDLEventHandler*> handlers;
public:
	SDLEventDispatcher(){}
	void add(SDLEventHandler* handler) {
		this->handlers.push_back(handler);
	}
	void dispatchEvents(float dts){
		SDL_Event event;
		while (SDL_PollEvent(&event)) {
			for (unsigned int i = 0; i < handlers.size(); i++) {
				handlers[i]->setEvent(event);
				handlers[i]->handleEvent(dts);
			}
		}
	}
	virtual ~SDLEventDispatcher() {
		for (unsigned int i = 0; i < handlers.size(); i++) {
			delete handlers[i];
		}
	}
};

#endif /* SDLEVENTDISPATCHER_H_ */
